/**
 *
 */
package jp.seraph.cui;

import jp.seraph.cui.message.MessageUtil;

/**
 *
 *
 */
public abstract class AbstractNode implements SystemNode {
    public AbstractNode(Mode aParent, InternalConsole aConsole) {
        mParent = aParent;
        mConsole = aConsole;
    }

    private Mode mParent;
    private InternalConsole mConsole;

    /**
     *
     * @see jp.seraph.cui.SystemNode#getParent()
     */
    public Mode getParent() {
        return mParent;
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#setParent(jp.seraph.cui.Mode)
     */
    public void setParent(Mode aParent) {
        if(mParent == aParent)
            return;

        mParent = aParent;
    }

    protected InternalConsole getConsole(){
        return mConsole;
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#delete()
     */
    public void delete() {
        if(this.isRoot())
            throw new UnsupportedOperationException(MessageUtil.cannotDeleteRootMode());

        Mode tParent = this.getParent();
        tParent.deleteChild(this);
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#isRoot()
     */
    public boolean isRoot() {
        return this.equals(this.getParent());
    }
}
